#define quickread
#ifdef quickread
#include <cstdio> 
template <typename T>
inline void read(T& x)
{
    int c=getchar(), f=1; x=0;
    while(c<'0'||'9'<c) {if(c=='-') f=-1; c=getchar();}
    while('0'<=c&&c<='9') 
        x=(x<<3)+(x<<1)+c-'0', c=getchar();
    x*=f;
}
template <typename T>
inline void quickwrite(T x)
{
    if(x<0) putchar('-'), x*=-1;
    if(x>=10) quickwrite(x/10);
    putchar(x%10+'0');
}
#else 
#include <iostream>
#endif
#include <algorithm>
using namespace std;
#define DEBUG
const int N=2e5+10;
int n, q;
int a[N], p[N]; //排名(下表为编号) 编号(下标为排名)
int op, x;
void init()
{
    read(n), read(q);
    for(int i=1; i<=n; i++) read(a[i]), p[a[i]]=i;
}

void solve()
{
    init();
    while(q--)
    {
        read(op), read(x);
        if(op==1)
        {
            int rank=a[x];
            if(rank==1) continue; //排名为1，跳过
            swap(a[p[rank]], a[p[rank-1]]); //交换两人的编号和排名
            swap(p[rank], p[rank-1]);
        }
        else if(op==2) quickwrite(p[x]), puts("");
        else if(op==3) quickwrite(a[x]), puts("");
    }
}

// #undef DEBUG
signed main()
{
    #ifdef DEBUG
        freopen("../in.txt", "r", stdin);
        freopen("../out.txt", "w", stdout);
    #endif
    #ifndef quickread
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #endif

    int T=1; //scanf("%d", &T);
    while(T--) 
    {
        solve();
    }
    return 0;
}
